<?php
namespace app\serverintegralmall\logic;
use \app\manage\logic\BaseLogic;
use \app\manage\service\ApiBase;

/**
 * @author:      李颖
 * @DateTime:    2017-11-02 14:23:22
 * @Description: 积分商品
 */

class Goods extends BaseLogic{

	protected $goodsLogic = '\app\serverintegralmall\logic\Goods';
    protected $goodsValidate = '\app\serverintegralmall\validate\Goods';


    /*艺货后台发布积分商品*/
    public function addIntegralGoods($data): array 
    {
    	//获取基本信息
    	$service = new ApiBase($data['token']);
        $app_key = \app\manage\service\ApiBase::getAppKey();
        $getBase['query'] = json_encode([
            ['path'=>'serveruser/auth/Token/hGetAll', 'param'=>['token'=>$data['token']]],
            ['path'=>'serveruser/auth/App/find', 'param'=>['app_key'=>$app_key]]
        ]);
        $baseInfo = $service->sendDataLots(config('proxy_all_url'), $getBase);
        if($baseInfo['status'] != SUCCESS_STATUS){
            return $baseInfo;
        }
        //获取商品编码
        $getCode['query'] = json_encode([
            ['path'=>'servercoding/coding/Coding/getCoding', 'param'=>['type'=>'goods','token'=>$data['token'],'app_id'=>$baseInfo['res'][1]['id']]]
        ]);
        $codeInfo = $service->sendDataOne(config('proxy_all_url'), $getCode);
        if($codeInfo['status'] != SUCCESS_STATUS){
            return $codeInfo;
        }
        //发布商品
        $data['user_id'] = $baseInfo['res'][0]['id'];
        $data['app_id'] = $baseInfo['res'][1]['id'];
        $data['product_code'] = $codeInfo['res']['autoRes'];
        
        $addGoods['query'] = json_encode([
            ['path'=>'serverintegralmall/goods/Goods/addIntegralGoods', 'param'=>$data]
        ]);
        return $service->sendDataOne(config('proxy_all_url'), $addGoods);
    }




}